//返回ID对象
var g = function(id){
	return document.getElementById(id);
}

//验证的ID
var smid = g("makeupCo");
var cphone = g("cphone");
var cidb = g("cidb");
var ctid = g("ctid");
var cdate = g("cdate");
var caddress = g("caddress");
var customer = g("customer");

//错误提示
var smidmsg = g("smidmsg");
var cphonemsg = g("cphonemsg");
var cidbmsg = g("cidbmsg");
var ctidmsg = g("ctidmsg");
var cdatemsg = g("cdatemsg");
var caddressmsg = g("caddressmsg");
var customermsg = g("customermsg");

//接案员验证
function smidCheck(){
	if(smid.value == "" || smid.value == null){
		g("makeupCoSe").style.border = "1px solid";
		g("makeupCoSe").style.borderColor = "red";
		smidmsg.innerHTML = "<font color='red' size='1px'>请选择接案员！</font>";
		return false;
	}else{
		g("makeupCoSe").style.border = "";
		g("makeupCoSe").style.borderColor = "";
		smidmsg.innerHTML = "";
		return true;
	}
}

//客户验证
function customerCheck(){
	if(customer.value == "" || customer.value == null){
		customer.style.border = "1px solid";
		customer.style.borderColor = "red";
		customermsg.innerHTML = "<font color='red' size='1px'>请填写客户名称！</font>";
		return false;
	}else if(cidb.value == "" || cidb.value == null){
		customer.style.border = "1px solid";
		customer.style.borderColor = "red";
		customermsg.innerHTML = "<font color='red' size='1px'>请填写客户不存在！</font>";
		return false;
	}else{
		customer.style.border = "";
		customer.style.borderColor = "";
		customermsg.innerHTML = "";
		return true;
	}
}

//客户校验
customer.onblur = function(){
	getCar();	
	customerCheck();
}

//手机验证
function cphoneCheck(){
	var phoneRegex = /^[1][358][0-9]{9}$/;	//正则表达式
	
	if(cphone.value == "" || cphone.value == null){
		cphone.style.border = "1px solid";
		cphone.style.borderColor = "red";
		cphonemsg.innerHTML = "<font color='red' size='1px'>请填写手机号码！</font>";
		return false;
	}else if(!phoneRegex.test(cphone.value)){
		cphone.style.border = "1px solid";
		cphone.style.borderColor = "red";
		cphonemsg.innerHTML = "<font color='red' size='1px'>您填写的手机号码格式不对！请核对后重新填写~</font>";
		return false;
	}else{
		cphone.style.border = "";
		cphonemsg.innerHTML = "";
		return true;
	}
}

//车辆验证
function cidbCheck(){
	if(cidb.value == "" || cidb.value == null){
		cidb.style.border = "1px solid";
		cidb.style.borderColor = "red";
		cidbmsg.innerHTML = "<font color='red' size='1px'>请选择您的车辆！</font>";
		return false;
	}else{
		cidb.style.border = "";
		cidbmsg.innerHTML = "";
		return true;
	}
}

//案件类型验证
function ctidCheck(){
	if(ctid.value == "" || ctid.value == null){
		ctid.style.border = "1px solid";
		ctid.style.borderColor = "red";
		ctidmsg.innerHTML = "<font color='red' size='1px'>请选择案件类型！</font>";
		return false;
	}else{
		ctid.style.border = "";
		ctidmsg.innerHTML = "";
		return true;
	}
}

//案发日期验证
function cdateCheck(){
	//获取当前时间
	var date = new Date();
	var year = date.getYear()+1900;
	var mon = date.getMonth()+1;
	var day = date.getDate();

	//如果日期是个位数就在前面加个0
	if(day < 10){
		day = "0" + day; 
	}
	
	//拼接当前日期用来做比较
	var nNowDate = year + "/" + mon + "/" + day;
	
	//拼接案发日期用来做比较
	var cdateV = cdate.value.split('-');
	var nCadateV = cdateV[0] + "/" + cdateV[1] + "/" + cdateV[2];
	
	if(cdate.value == "" || cdate.value == null){
		cdate.style.border = "1px solid";
		cdate.style.borderColor = "red";
		cdatemsg.innerHTML = "<font color='red' size='1px'>请填写案发日期！</font>";
		return false;
	}else if(nCadateV > nNowDate){
		cdate.style.border = "1px solid";
		cdate.style.borderColor = "red";
		cdatemsg.innerHTML = "<font color='red' size='1px'>请填写正确的日期！不能大于今天的日期~</font>";
		return false;
	}else{
		cdate.style.border = "";
		cdatemsg.innerHTML = "";
		return true;
	}
}

//案件地址验证
function caddressCheck(){
	if(caddress.value == "" || caddress.value == null){
		caddress.style.border = "1px solid";
		caddress.style.borderColor = "red";
		caddressmsg.innerHTML = "<font color='red' size='1px'>请填写案件地址！</font>";
		return false;
	}else{
		caddress.style.border = "";
		caddressmsg.innerHTML = "";
		return true;
	}
}


function checkAll(){
	return smidCheck() && cphoneCheck() && cidbCheck() && ctidCheck() && cdateCheck() && caddressCheck() && cdescCheck();
}

function checkAll2(){
	return smidCheck() || cphoneCheck() || cidbCheck() || ctidCheck() || cdateCheck() || caddressCheck() || cdescCheck();
}

function checkSysAll(){
	return customerCheck() && cphoneCheck() && cidbCheck() && ctidCheck() && cdateCheck() && caddressCheck();
}
function checkSysAll2(){
	return customerCheck() || cphoneCheck() || cidbCheck() || ctidCheck() || cdateCheck() || caddressCheck();
}